/*
 * @Descripttion: 
 * @version: 
 * @Author: lsy
 * @Date: 2022-01-25 09:26:19
 * @LastEditors: lsy
 * @LastEditTime: 2022-01-27 10:03:12
 */

// 必须第一个引用
import '@/qiankun/public-path';

import { createApp } from 'vue'
import App from './App.vue'

import router from "@/router"

let instance = null;
function render(props = {}) {
    const { container } = props;
    let ele = container ? container.querySelector('#app') : '#app';
    let instance = createApp(App);

    // 主子系统通讯,必须绑定在各子系统实列上，绑定在window上，onGlobalStateChange会相互覆盖
    if (window.__POWERED_BY_QIANKUN__) {
        instance.use((app) => {
            app.config.globalProperties.onGlobalStateChange = props.onGlobalStateChange;
            app.config.globalProperties.setGlobalState = props.setGlobalState;
        })
    }

    instance.use(router).mount(ele)
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
    render();
}
// 必须有的qiankunjs的生命周期
export async function bootstrap() {
    console.log('[vue] vue app bootstraped');
}
export async function mount(props) {
    console.log('[vue] props from main framework', props);
    render(props);
}
export async function unmount() {
    instance.$destroy();
    instance.$el.innerHTML = '';
    instance = null;
}
// 可选
export async function update(props) {
    console.log("update props", props);
}
